﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using fast_clipboard.viewmodel;
using FastHotKeyForWPF;

namespace fast_clipboard
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = new MainVM();
        }

        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);
            GlobalHotKey.Awake();
            Box1.ConnectWith(Paste1);

            Box2.ConnectWith(Paste2);

            Box3.ConnectWith(Paste3);
            //无论哪种 Box ，连接操作只需要执行一次

            Box1.SetHotKey(ModelKeys.CTRL, NormalKeys.Q, Paste1);
            Box2.SetHotKey(ModelKeys.CTRL, NormalKeys.W, Paste2);
            Box3.SetHotKey(ModelKeys.CTRL, NormalKeys.E, Paste3);
        }

        private void Paste1()
        {
            TextRange textRange = new TextRange(richBox1.Document.ContentStart, richBox1.Document.ContentEnd);
            string xw = textRange.Text;
            Clipboard.SetDataObject(xw);
        }

        private void Paste2()
        {
            TextRange textRange = new TextRange(richBox2.Document.ContentStart, richBox2.Document.ContentEnd);
            string xw = textRange.Text;
            Clipboard.SetDataObject(xw);
        }

        private void Paste3()
        {
            TextRange textRange = new TextRange(richBox3.Document.ContentStart, richBox3.Document.ContentEnd);
            string xw = textRange.Text;
            Clipboard.SetDataObject(xw);
        }

        protected override void OnClosed(EventArgs e)
        {
            GlobalHotKey.Destroy();
            ReturnValueMonitor.Destroy();

            base.OnClosed(e);
        }
    }
}